package com.st.springts.mapper;

import com.st.springts.entity.Department;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DepartmentMapper {

    @Select("select id,name,parent_id as parentId,description from department")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "parentId", column = "parent_id"),
            @Result(property = "description", column = "description")
    })
    List<Department> findAll();

@Insert("insert into department(name, parent_id, description) values (#{name},#{parentId},#{description})")
@Options(useGeneratedKeys = true,keyProperty = "id")
    void insert(Department department);

@Update("update department set name=#{name},parent_id=#{parentId}, description=#{description} where id=#{id}")
void update(Department department);

    @Delete("DELETE FROM department WHERE id=#{id}")
    void delete(Long id);
// //   @Select("SELECT * FROM department WHERE parent_id is null ")
//    List<Department> findRootDepartments();
//
// //   @Select("select * from department where parent_id=#{parentId}")
//    List<Department> findByParentId(Long parentId);
//
// //   @Select("select * from department")
//    List<Department> findAll();
//
//    Department findById(Long id);

}
